﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MaxStudio.Concrete.DBUtility;
using MaxStudio.Concrete.Server.Dao;
using MaxStudio.Concrete.Server.Interface;

namespace MaxStudio.Concrete.Server.Service
{
    public class PumperService : ServiceHandle, IPumper
    {
        #region IPumper Members

        public OperationResult<List<tb_Pumper>> GetAllPumper()
        {
            OperationResult<List<tb_Pumper>> result = new OperationResult<List<tb_Pumper>>();
            ConcreteDaoDataContext dataContext = getDateContext();
            List<tb_Pumper> list = new List<tb_Pumper>();
            try
            {
                list = dataContext.GetAllPumper();
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_Pumper>> GetPumperBySalesOrderId(int salesOrderId)
        {
            OperationResult<List<tb_Pumper>> result = new OperationResult<List<tb_Pumper>>();
            ConcreteDaoDataContext dataContext = getDateContext();
            List<tb_Pumper> list = new List<tb_Pumper>();
            try
            {
                list = dataContext.GetPumperBySalesOrderId(salesOrderId);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_Pumper> GetPumperById(int id)
        {
            OperationResult<tb_Pumper> result = new OperationResult<tb_Pumper>();
            ConcreteDaoDataContext dataContext = getDateContext();
            tb_Pumper pumper;
            try
            {
                pumper = dataContext.GetPumperById(id);
                if (pumper == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = pumper;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_Pumper> CreatePumper(tb_Pumper entity)
        {
            OperationResult<tb_Pumper> result = new OperationResult<tb_Pumper>();
            ConcreteDaoDataContext dataContext = getDateContext();

            try
            {
                dataContext.CreatePumper(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_Pumper> ModifyPumper(tb_Pumper entity)
        {
            OperationResult<tb_Pumper> result = new OperationResult<tb_Pumper>();
            ConcreteDaoDataContext dataContext = getDateContext();

            try
            {
                dataContext.ModifyPumper(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_Pumper> DeletePumper(tb_Pumper entity)
        {
            OperationResult<tb_Pumper> result = new OperationResult<tb_Pumper>();
            ConcreteDaoDataContext dataContext = getDateContext();

            try
            {
                dataContext.DeletePumper(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        #endregion
    }
}
